package com.xinqi.modules.sys.gpt.service.impl;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.modules.sys.gpt.convert.DayCountConvert;
import com.xinqi.modules.sys.gpt.dto.rsp.DayCountResultDTO;
import com.xinqi.modules.sys.gpt.manager.DayCountManager;
import com.xinqi.modules.sys.gpt.service.DayCountService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.Objects;

/**
 * 每日用户配额服务层实现
 *
 * @author: yyzhen
 * @date: 2023/05/23
 */
@Validated
@Service("dayCountService")
@RequiredArgsConstructor
public class DayCountServiceImpl implements DayCountService {
    private final DayCountConvert dayCountConvert;
    private final DayCountManager dayCountManager;

    /**
     * 获取用户今日配额（此方法初始化用户配额）
     *
     * @param userId
     * @return
     */
    @Override
    public DayCountResultDTO findByUserAndInit(Long userId) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(userId), MessageUtils.message("user.id.not.black"));
        return dayCountConvert.convert(dayCountManager.findByUserAndInit(userId));
    }

}
